import { defineStore } from 'pinia';

// 用户信息
const userInfo = uni.getStorageSync("userInfo") || {
	_id: "",
	nickName: ""
};

// 用户token
const utoken = uni.getStorageSync('utoken') || {
	token: "",
	tokenExpired: ""
};

// 根字体大小
const rootFont = uni.getStorageSync('rootFont') || "24rpx";

export const appStore = defineStore('appStore', {
	state: () => {
		return { 
			// token
			utoken: utoken,
			// 用户信息
			userInfo: userInfo,
			// 根字体大小
			rootFont: rootFont,
			activeTabIndex: -1,
		};
	},
	actions: {
	},
	getters: {
		isLogin(state: any){
			if(state.utoken.token.length > 0){
				
				if(state.utoken.tokenExpired){
					
					let now = Number(new Date().getTime());
					
					if(now > Number(state.utoken.tokenExpired)){
						return false;
					}else{
						return true;	
					}
					
				}
				
				return true;
			}else{
				return false;
			}
		}
	}
});

